<template>
	<view class="move">
		<view class="ey same">
			<text class="car">车牌号</text>
			<view class="put">
				<up-input placeholder="请输入车牌号" border="surround" v-model="carnum" @blur="checknum"></up-input>
			</view>
		</view>

		<view class="ey same">
			<text class="car">身份证号</text>
			<view class="put">
				<up-input placeholder="请输入身份证号" border="surround" v-model="idcard" @blur="checkid"></up-input>
			</view>
		</view>

		<view class="ey same">
			<text class="car">联系电话</text>
			<view class="put">
				<up-input placeholder="请输入联系电话" border="surround" v-model="phone" @blur="checkphone"></up-input>
			</view>
		</view>

		<view class="ey same">
			<text class="car">省</text>
			<view class="put">
				<up-input placeholder="请输入省份" border="surround" v-model="province" @blur="checkprovince"></up-input>
			</view>
		</view>

		<view class="ey same">
			<text class="car">市</text>
			<view class="put">
				<up-input placeholder="请输入市" border="surround" v-model="city" @blur="checkcity"></up-input>
			</view>
		</view>

		<view class="ey same">
			<text class="car">区</text>
			<view class="put">
				<up-input placeholder="请输入区" border="surround" v-model="area" @blur="checkarea"></up-input>
			</view>
		</view>

		<view class="ey same">
			<text class="car">详细地址</text>
			<view class="put">
				<up-input placeholder="请输入详细地址" border="surround" v-model="address" @blur="checkaddress"></up-input>
			</view>
		</view>

		

		<up-button type="primary" text="查询" @click="getsub"></up-button>

	</view>
</template>

<script setup>
	import {ref} from 'vue';
	import {historycart} from '@/api/parkApi.js'
	import {mvcart} from '@/mock/park.js'

	const fileList1 = ref([]) //图片路径 显示在页面上
	const carnum = ref() //车牌号
	const idcard = ref() //身份证号
	const phone = ref() //电话
	const province = ref() //省份
	const city = ref() //市
	const area = ref() //区
	const address = ref() //详细地址 
	const imgurl = ref() //图片地址
    const movecart = ref() //挪车记录


    //失去焦点触发
	const check=(val)=>{
			
		if(val==undefined){
			uni.showToast({
				title:'内容不能为空',
				icon:'error'
			})
		}
	}
	
    //失去焦点检查车牌
	const checknum=()=>{
		check(carnum.value)
	}
	
	//失去焦点检查身份
	const checkid=()=>{
		check(idcard.value)
	}

    //失去焦点检查电话
    const checkphone=()=>{
    	check(phone.value)
    }
	
	//失去焦点检查省
	const checkprovince=()=>{
		check(province.value)
	}

    //失去焦点检查市
    const checkcity=()=>{
    	check(city.value)
    }
	
	//失去焦点检查区
	const checkarea=()=>{
		check(area.value)
	}
	
	//失去焦点检查详细地址
	const checkaddress=()=>{
		check(address.value)
	}

	//提交申请
	const getsub = async () => {

		if (carnum.value == undefined || idcard.value == undefined || phone.value == undefined || province.value ==
			undefined || city.value==undefined || area.value==undefined || address.value==undefined ) {
             uni.showToast({
             	title:'内容不能为空',
				icon:'error'
             })
             return;
		}

		let res = await historycart({
			header:{
				"Authorization":uni.getStorageSync('token')
			},
			data:{
				plateNo:carnum.value,
				idCard:idcard.value,
				tel:phone.value,
				province:province.value,
				city:city.value,
				area:area.value,
				address:address.value,

			}
		})
		
		 if(res.code==200){
			movecart.value=res.rows
			
			uni.navigateTo({
				url:`/pages/park/cart/movecart/movede/movede?mcart=${JSON.stringify(movecart.value)}`
			})
		}else{
			//模拟数据
			
			if(mvcart(carnum.value).length==0){
				uni.showToast({
					title:'暂无挪车记录',
					icon:'error'
				})
				return
			}
			movecart.value=mvcart(carnum.value)[0]
			
			uni.navigateTo({
				url:`/pages/park/cart/movecart/movede/movede?carnum=${mvcart(carnum.value)[0].carnum}&idcard=${mvcart(carnum.value)[0].idcard}&phone=${mvcart(carnum.value)[0].phone}&province=${mvcart(carnum.value)[0].province}&city=${mvcart(carnum.value)[0].city}&area=${mvcart(carnum.value)[0].area}&address=${mvcart(carnum.value)[0].address}&src=${mvcart(carnum.value)[0].src}`
			})
			
		}
		console.log(movecart.value);
	}
	
</script>
<style lang="scss">
	.move {
		padding: 8px 14px;

		.ey {
			display: flex;
			align-items: center;

			.car {
				flex: 1;
				font-size: 18px;
				font-weight: 700;
				text-align-last: justify;
				margin-right: 14px;

			}

			.put {
				flex: 3;
			}
		}

		.same {
			margin: 10px 0px;
		}

		::v-deep .u-button {
			margin: 10px 0px;
		}
	}
</style>